<?php


namespace app\api\controller;

use app\common\service\companyIndustry\industrymodel\TsinghuaDrainEmissionToFacilityParam;
use app\common\service\companyIndustry\realtime\NitreEmissionService;
use app\common\service\companyIndustry\realtime\RealtimeEmissionService;
use app\common\service\companyIndustry\realtime\SulfurEmissionService;
use app\common\service\companyIndustry\realtime\SulfurLiquidGasRatioService;
use app\common\service\companyIndustry\realtime\SulfurLiquidGasRatioService as RealSo2Liquid;
use app\common\service\companyIndustry\realtime\SulfurPumpService;
use app\common\service\companyIndustry\realtime\SulfurSlurrySupplyService;
use app\common\service\companyIndustry\realtime\SulfurSlurrySupplyService as RealSo2Slurry;
use app\common\service\companyIndustry\simulation\SimulationConcentrationService;
use app\common\service\companyIndustry\simulation\SimulationEfficiencyService;
use app\common\service\companyIndustry\simulation\SimulationEmissionService;
use app\common\service\companyIndustry\simulation\SimulationGasOutService;
use app\common\service\companyIndustry\tsinghua\SulfurConcentrationService as TsinghuaSo2Con;
use app\common\service\companyIndustry\tsinghua\SulfurEfficiencyService as TsinghuaSo2Effi;
use app\common\service\companyIndustry\tsinghua\TsinghuaEmissionService;
use app\common\service\CompanyService;
use app\common\service\ControlEmissionService;
use app\common\service\ControlService;
use app\common\service\EmissionService;
use app\common\service\FlugGasService;
use app\common\service\FormulaService;
use app\common\service\MongoService;
use app\common\service\SimulationIndustryService;

class Test extends BaseController
{
    //管控第四步减排量
    public function test1()
    {
        $emission = new EmissionService();
        //step1：管控期间原始排放量
        $dataOrigin = $emission->getTsinghuaTimesOriginCompanyEmissionTotalComaanyHourAvg('CZ2019-07-24 001号', 't');
        //step2：清华方案排放量
        $dataTsingPlan = $emission->getTsinghuaPlanTotalEmissionHourAvg('CZ2019-07-24 001号', 't');
        //step3：得到目标排放量
        $targetEmission = [];
        $formula        = new FormulaService();
        foreach ($dataTsingPlan as $k => $v) {
            $targetEmission[$k]['tsinghua_plan_id']     = $v['tsinghua_plan_id'];
            $targetEmission[$k]['tsinghua_plan_name']   = $v['tsinghua_plan_name'];
            $targetEmission[$k]['target_emissions_so2'] = $formula->targetEmission($dataOrigin['so2_emissions'], $v['tsinghua_emission_so2']);
            $targetEmission[$k]['target_emissions_no2'] = $formula->targetEmission($dataOrigin['no2_emissions'], $v['tsinghua_emission_no2']);
            $targetEmission[$k]['target_emissions_tsp'] = $formula->targetEmission($dataOrigin['tsp_emissions'], $v['tsinghua_emission_tsp']);
            $targetEmission[$k]['unit']                 = $v['tsinghua_unit'];
        }

        print_r($dataOrigin);
        print_r($dataTsingPlan);
        print_r($targetEmission);
        exit;
    }

    //管控
    public function control()
    {
        $control = new ControlService();
        $result  = $control->getControlDays('CZ2019-06-24 001号');
        return $result;
    }

    //（模拟企业）减排前浓度
    //返回：0.35 0.286436s ShowPageTrace
    public function beforeNongdu()
    {
        $simulation = new SimulationConcentrationService();
        $data       = $simulation->getBeforeSimulationConcentrationByCompanyId(2, 'so2');
        print_r($data);
    }

    //（模拟企业）减排前效率
    //返回：0.95
    public function beforeXiaolv()
    {
        $simulation = new SimulationEfficiencyService();
        $data       = $simulation->getBeforeSimulationEfficiencyByCompanyId(2, 'so2');
        print_r($data);
    }

    //（模拟企业）减排前烟气量
    //返回：16396080
    public function beforeYanqiliang()
    {
        $simulation = new SimulationGasOutService();
        $data       = $simulation->getBeforeFlueGas(3, 5); //公司ID3，5天
        print_r($data);
    }

    //（模拟企业）减排前排放量
    //返回：10560362.4
    public function beoforePaifanglaing()
    {
        $simulation = new SimulationEmissionService();
        $data       = $simulation->getSimulationEmissionWayOne(3, 5, 'SO2'); //公司ID3，5天，污染物SO2
        print_r($data);
    }

    //（清华方案）排放量
    //
    //Array
    //(
    //    [10] => Array
    //        (
    //            [id] => 54
    //            [company_id] => 5
    //            [company_name] => 山西漳泽电力股份有限公司漳泽发电分公司
    //            [drain_id] => 10
    //            [drain_name] => 1#
    //            [tsinghua_emission] => 460434.51908768
    //            [tsinghua_emission_unit] => mg
    //        )
    //
    //    [11] => Array
    //        (
    //            [id] => 55
    //            [company_id] => 5
    //            [company_name] => 山西漳泽电力股份有限公司漳泽发电分公司
    //            [drain_id] => 11
    //            [drain_name] => 2#
    //            [tsinghua_emission] => 460434.51908768
    //            [tsinghua_emission_unit] => mg
    //        )
    //
    //    [12] => Array
    //        (
    //            [id] => 56
    //            [company_id] => 5
    //            [company_name] => 山西漳泽电力股份有限公司漳泽发电分公司
    //            [drain_id] => 12
    //            [drain_name] => 3#
    //            [tsinghua_emission] => 460434.51908768
    //            [tsinghua_emission_unit] => mg
    //        )
    //)
    public function tsinghuaPaifangliang()
    {
        $simulation = new SimulationIndustryService();
        $data       = $simulation->getTsinghuaPlanEmission(5, 'CZ2019-06-24 001号', '方案1', 'SO2'); //公司ID3，5天，污染物SO2
        print_r($data);
    }

    //获取管控清单企业的ID
    //返回：1,2,4,5,6,7,8,9,10,11,13,14,15,16,19,20,21,22,23,24,25,28,29,30,31,32,33,34,36,37,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60
    public function qingdangongsi()
    {
        $control = new ControlService();
        $result  = $control->getControlListCompanyIds('CZ2019-07-16 001号');
        print_r($result);
    }

    //供浆量
    public function beforeGongjiangliang()
    {
        $slurry = new SulfurSlurrySupplyService();
        $result = $slurry->singleCompanySingleDrainSingleFacility(3, 'CZ2019-08-10 001号');
        $this->success('success', $result);
    }


    //循环泵
    public function beforeXunhuanben()
    {
        $pump = new SulfurPumpService();
        $data = $pump->singleCompanySingleDrainSingleFacility(3, 'CZ2019-08-10 001号');
        print_r($data);
    }

    //液气比
    public function beforeYeqibi()
    {
        $liquid = new SulfurLiquidGasRatioService();
        $data   = $liquid->singleCompanySingleDrainSingleFacilityDetails('CZ2019-08-10 001号', 3);
        print_r($data);
    }

    //脱硫单设施排放量
    public function beforeTuoliuSheshi()
    {
        $sulfur = new SulfurEmissionService();
        $result = $sulfur->beforeSingleCompanySingleDrainSingleFacilityHourAverage(3, 'CZ2019-07-24 001号');
        $this->success('success', $result);
    }

    //脱硝单设施排放量
    public function beforeTuoXiaoSheshi()
    {
        $nitre  = new NitreEmissionService();
        $result = $nitre->beforeSingleCompanySingleDrainSingleFacilityTotal(1, 'CZ2019-07-24 001号');
        $this->success('success', $result);
    }

    //获取设施类型
    public function getType()
    {
        $company = new CompanyService();
        $result  = $company->getTypeByFacilityId(3);
        print_r($result);
    }

    //设施排放量（小时平均）-杨毅
    public function beforeSheshiPaifangliangXiaoshi()
    {
        $emission = new ControlEmissionService();
        $result   = $emission->getControlEmissionHourAverageByFacilityId(6, 'CZ2019-07-24 001号');
        $this->success('success', $result);
    }

    //设施排放量（天平均）（加true是每天的排放量）-安瑶瑶
    public function beforeSheshiPaifangliangTian()
    {
        $emission = new ControlEmissionService();
        $result   = $emission->getControlEmissionDayAverageByFacilityId(6, 'CZ2019-08-01 001号', true);
        $this->success('success', $result);
    }

    //企业排口排放量 - 小时平均
    public function moniPaifangliangXiaoshi()
    {
        $emission = new ControlEmissionService();
        $result   = $emission->getSingleDrainEmissionsHourAvg(1, 'CZ2019-08-14 001号');
        $this->success('success', $result);
    }


    //模拟企业排口排放量 - 小时平均
    public function moniPaifangliangTian()
    {
        $emission = new ControlEmissionService();
        $result   = $emission->getSingleDrainEmissionsDayAvg(1, 'CZ2019-07-24 001号');
        $this->success('success', $result);
    }

    //脱硫每小时
    public function tuoliuMeixioshi()
    {
        $sulfur = new SulfurEmissionService();
        $result = $sulfur->beforeSingleCompanySingleDrainEveryHour(1, 'CZ2019-07-24 001号');
        print_r($result);
    }

    //脱硫每小时
    public function tuoxiaoMeixioshi()
    {
        $nitre = new NitreEmissionService();
        $result = $nitre->beforeSingleCompanySingleDrainEveryHour(1, 'CZ2019-07-24 001号');
        print_r($result);
    }

    //李博士模型
    public function liboshimoxing()
    {
        $tsinghua = new TsinghuaDrainEmissionToFacilityParam();
        $result = $tsinghua->getOperationConcentrationAndEfficiencyProjectValue('CZ2019-07-25 001号', '方案1', [3, 6], 'SO2');
        print_r($result);exit;
    }

    //方案的运行浓度和运行效率
    public function fangannongduxioalv()
    {
        $tsinghua = new TsinghuaDrainEmissionToFacilityParam();
        $result = $tsinghua->getPlanParamByFacilityId(3,  'CZ2019-07-25 001号', '方案1',  'SO2');
        print_r($result);exit;
    }

    //减排前单个公司排放量
    public function dangegongsiPaifangliang()
    {
        $emission = new EmissionService();
        $result = $emission->controlSingleCompanyTotalEmission(3, 'CZ2019-07-25 001号', 'NO2');
        print_r($result);exit;
    }

    //行业排放量
    public function hangyePaifangliang()
    {
        $emission = new ControlEmissionService();
        $result  = $emission->controlSingleIndustryTotalEmission(1, 'CZ2019-07-25 001号', 'SO2');
        print_r($result);exit;
    }

    //（减排前）获取7天的排放量具体
    public function meitianJuti()
    {
        $emission = new ControlEmissionService();
        $result = $emission->getSingleDrainEmissionDetailsEveryDay(1, 'CZ2019-07-24 001号');
        print_r($result);exit;
    }

    //（方案值）获取管控期间的排放量
    public function fananMeixiaoshi()
    {
        $tsinghua = new TsinghuaEmissionService();
        $tsinghua->getTsinghuaSingleCompanyEmissionType();
    }

    //（减排前）行业排放量
    public function hangyePaifan()
    {
        $emission = new ControlEmissionService();
        $result = $emission->controlEveryIndustryTotalEmission('CZ2019-07-31 001号');
        print_r($result);exit;
    }

    //（方案值）小时-天趋势图
    public function qinghuaXiaohiQushitu()
    {
        $tsinghua = new TsinghuaEmissionService();
        $result = $tsinghua->getTsinghuaSingleCompanySingleDrainEmission('so2', 1, 'CZ2019-07-31 001号', 1, '方案1', 'kg','day');
        print_r($result);exit;
    }

    //供浆量
    public function gongjiangliang()
    {
        $beforeSulfurSlurryService = new RealSo2Slurry();
        $result = $beforeSulfurSlurry        = $beforeSulfurSlurryService->singleCompanySingleDrainSingleFacility(3);
        print_r($result);exit;
    }

    //方案运行浓度
    public function fangannongdu()
    {
        $planConcentrationService = new TsinghuaSo2Con();
        $result = $planConcentration        = $planConcentrationService->singleCompanySingleDrainSingleFacility('CZ2019-07-31 001号', '方案1', 3);
        print_r($result);exit;
    }

    //方案运行效率
    public function fanganxiaolv()
    {
        $planEfficiencyService = new TsinghuaSo2Effi();
        $planEfficiency        = $planEfficiencyService->singleCompanySingleDrainSingleFacility('CZ2019-07-31 001号', '方案1', 3);
        print_r($planEfficiency);exit;
    }

    //液气比
    public function yeqibi()
    {
        $beforeSulfurLiquidService = new RealSo2Liquid();
        $result = $beforeSulfurLiquidDetails = $beforeSulfurLiquidService->singleCompanySingleDrainSingleFacilityDetails(3);
        print_r($result);exit;
    }

    //获取排口减排量 - 冀云要
    public function jianpailian()
    {
        $emission = new ControlEmissionService();
        //$result = $emission->getReductionEmission('CZ2019-07-31 001号', 'so2', '方案1');
        $result = $emission->getReductionEmission('CZ2019-07-31 001号', 'no2', '方案1');
        print_r($result);exit;
    }
    
    public function getSingleCompanyEmissionMinToHourAvg()
    {
        $emission = new EmissionService();
        $result  = $emission->getSingleCompanyDrainEmissionMinToHourAvg(1, '2019-08-09', 3, 'kg');
        print_r($result);
    }

    public function getSingleCompanyDrainEmissionMinToHourAvg()
    {
        $emission = new EmissionService();
        $result  = $emission->getSingleCompanyDrainEmissionMinToHourAvg(2);
        print_r($result);
    }

    public function getAllCompanyEmissionMinToHourAvg()
    {
        $emission = new EmissionService();
        $result = $emission->getAllCompanyEmissionMinToHourAvg('yesterday', 7);
        print_r($result);exit;
    }

    //（减排前）获取168小时的排放量 - 朱耿/冀云要
    public function meixiaoshiJuti()
    {
        $emission = new ControlEmissionService();
        //减排前
        $result = $emission->getSingleDrainEmissionDetailsEveryHour(3, 'CZ2019-08-01 001号', 'before');
        //方案
        $result = $emission->getSingleDrainEmissionDetailsEveryHour(1, 'CZ2019-07-31 001号', 'control');
        print_r($result);exit;
    }

    public function getTsinghuaCompanyEmission()
    {
        $controlEmission = new ControlEmissionService();
//        $result = $controlEmission->getTsinghuaCompanyEmission('so2', 1, 'CZ2019-08-23 001号', '方案1',  'kg');
//        $result = $controlEmission->getTsinghuaCompanyEmission('so2', 1, 'CZ2019-08-23 001号', '方案2',  'kg');
        $result = $controlEmission->getTsinghuaCompanyEmission('so2', 1, 'CZ2019-08-23 001号', '方案3',  'kg');
        print_r($result);exit;
    }



    public function zhugeng()
    {
        $real = new RealtimeEmissionService();
        $result = $real->getRealtimeSingleCompanyDrainEmissionMinToHourAvg(1, '2018-08-16', 3, 'kg');
        print_r($result);exit;
    }

    public function test3()
    {
        $control = new ControlService();
        $result = $control->getControlStartTime("CZ2019-08-13 001号");
        print_r($result);exit;
    }

    public function test()
    {
        $control = new ControlEmissionService();
        //减排前
        //$result = $control->getSingleDrainEmissionDetailsEveryHour(3, 'CZ2019-08-01 001号', 'before');
        //方案值
        $result = $control->getSingleDrainEmissionDetailsEveryHour(1, "CZ2019-08-08 001号", 'plan', '方案1');
        print_r($result);exit;
    }

    //管控中方案值
    public function guankongzhong()
    {
        $control = new ControlEmissionService();
        //实时企业（管控中）
        $result1 = $control->getSingleDrainEmissionDetailsHourAvg(1, "CZ2019-08-13 001号", 'control', '方案1');
        echo "实时企业（管控中）<br/>";
        print_r($result1);
        echo "<hr/>";

        //模拟企业（管控中）
        $result2 = $control->getSingleDrainEmissionDetailsHourAvg(3, "CZ2019-08-13 001号", 'control', '方案1');
        echo "模拟企业（管控中）<br/>";
        print_r($result2);
        echo "<hr/>";

        //实时企业（清华）
        $result3 = $control->getSingleDrainEmissionDetailsHourAvg(1, "CZ2019-08-13 001号", 'plan', '方案1');
        echo "实时企业（清华）<br/>";
        print_r($result3);
        echo "<hr/>";

        //模拟企业（清华）
        $result4 = $control->getSingleDrainEmissionDetailsHourAvg(122, "CZ2019-08-13 001号", 'plan', '方案1');
        echo "模拟企业（清华）<br/>";
        print_r($result4);
        echo "<hr/>";
    }

    //朱耿要的
    public function step6()
    {
        $control = new ControlEmissionService();
        //实时企业
        $result1 = $control->getSingleDrainEmissionCompletionRate(1, 'CZ2019-08-14 001号',  '方案1', 'NO2');

        //模拟企业
        $result2 = $control->getSingleDrainEmissionCompletionRate(122, 'CZ2019-08-14 001号',  '方案1', 'NO2');
        print_r($result1);
        echo "<hr/>";
        print_r($result2);
        exit;
    }


}